<template>
  <Row type="flex">
    <Col flex="800px"> <h2 class="title2">已失效记录 <i>{{ config.page.total }}</i></h2></Col>
    <Col flex="350px"></Col>
  </Row>

  <Table
      :columns="config.columns"
      :row-key="record => record.punishActionId"
      :data-source="config.list"
      :pagination="config.page"
      :loading="config.loading"
      @change="(pagination)=> changeHandler(pagination, config)"
      bordered
  >
    <template #indexSlot="{ index }">{{(config.page.current-1)*10+index+1}}</template>
    <template #date="{ text,record }">
      <p class="mb0">因{{ record.punishReason }}，{{ parseTime(record.punishStartDate)}} ~ {{ parseTime(record.punishEndDate)}}期间内，不受理企业“<span class="orange">{{text}}</span>”资质申报业务</p>
    </template>


    <template #detail="{ text , record }">
      <span class="blue pointer" @click="permitDetail(record)">详情</span>
    </template>
  </Table>
  <Modal v-model:visible="visibleRef" :width="900" title="行为限制信息详情"
         :footer="null" :centered="true">
    <detail :detail="swDetail"/>
  </Modal>
</template>

<script lang="ts">
import {defineComponent, inject, onMounted, reactive, ref, toRefs} from 'vue';
import {Row, Col, Table, Input, Select, Button, Modal, Descriptions,} from 'ant-design-vue';
import { getExpireLimitApi  } from '/@/api/company';
import { parseTime } from '/@/utils';
import detail from '/@/views/servicemore/limit/detail.vue';
const columns = [
  { title: '序号', dataIndex: 'index', width: 70, align: 'center', slots: ({ customRender: 'indexSlot' }) },
  { title: '限制内容', dataIndex: 'limitAptName', width: 480,slots: { customRender: "date"}},
  { title: '处罚机关', dataIndex: 'punishOrgan' },
  { title: '决定日期', dataIndex: 'punishDate', width: 120,customRender: ({ text })=> parseTime(text)},
  {
    title: "操作",
    dataIndex: "procExplain",
    width: 100,
    slots: { customRender: "detail"}
  }
]

export default defineComponent({
  components: {
    Table , Row, Col, Input, Button, Select, Option: Select.Option,
    Modal,Descriptions,DescriptionsItem:Descriptions.Item,detail
  },
  setup() {
    const corpId = inject('corpId') as string;
    const loading = ref<boolean>(true);
    const swDetail = ref({});
    const visibleRef = ref(false);
    const dictionary = reactive({
      type:[]
    })

    const config = reactive({
      columns: columns,
      list: [],
      loading: false,
      page: {
        total: 0,
        current: 1
      }
    })


    const permitDetail =  (x) => {
      loading.value = true;
      visibleRef.value = true;
      swDetail.value = x;
      loading.value = false;
    };

    const changeHandler = (pagination, config) => {
      const { current } = pagination;
      let { loading, list, page } = toRefs(config);
      loading.value = true;
      getExpireLimitApi( { corpId, current }).then( ({ data,success }) => {
        if(success){
          let { records, current, total } = data;
          list.value = records;
          loading.value = false;
          page.value = {current, total};
        }
      })
    }


    const init = () => {
      changeHandler({current: 1}, config);

    }

    onMounted(init)

    return {
      config, changeHandler , dictionary , parseTime , permitDetail , loading ,swDetail,visibleRef
    }
  },
})
</script>

<style lang="less" scoped>

.ant-col{
  padding-top: 16px;
  margin-bottom: 8px;
}

.ant-select ,.ant-btn{
  width: 100%;
}

.ant-col.text-right{
  padding-right: 0 !important;
}

</style>
